﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ContosoUniversity.DAL;
using ContosoUniversity.Models;
using log4net;
using Microsoft.Ajax.Utilities;

namespace ContosoUniversity.Controllers
{
    public class HomeController : Controller
    {
        private CodeFirstContext db = new CodeFirstContext();
        private ILog _log = LogManager.GetLogger(typeof (HomeController));

        public ActionResult Index()
        {
            db.Database.Log = Console.Write;
            _log.Debug("aaa");
            return View();
        }

        public ActionResult About()
        {
            var data = from student in db.Students
                group student by student.EnrollmentDate
                into dateGroup
                select new EnrollmentDateGroup()
                {
                    EnrollmentDate = dateGroup.Key,
                    StudentCount = dateGroup.Count()
                };

            return View(data.ToList());
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}